package party.lovey.remote.utils;

import com.alibaba.fastjson.JSONObject;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;

/**
 * 序列化工具
 * Created by huhaichao on 2017/4/26.
 */
public class SerializeUtil {

    public static String toXML(Object o){
        XStream xstream = new XStream(new StaxDriver());
        return xstream.toXML(o);
    }

    public static Object fromXML(String xml){
        XStream xstream = new XStream(new StaxDriver());
        return xstream.fromXML(xml);
    }

    public static String toJson(Object o){
        return JSONObject.toJSONString(o);
    }

    public static <T>T fromJson(String json,Class<T> clazz){
        return JSONObject.parseObject(json,clazz);
    }
}
